<?php

/**
 * This is the model class for table "realty_base".
 *
 * The followings are the available columns in table 'realty_base':
 * @property string $realty_id
 * @property string $dt_start
 * @property string $dt_add
 * @property integer $type_realty
 * @property integer $city_id
 * @property integer $district_id
 * @property integer $cost
 * @property string $furniture
 * @property string $cooperation
 * @property string $call_status
 * @property string $last_call
 * @property string $subscribe_advert
 * @property integer $repair
 * @property string $phone
 * @property string $take
 * @property string $take_dt
 * @property string $demo
 * @property string $demo_dt
 * @property string $daily
 * @property integer $send_count
 * @property string $fordeleting
 * @property string $status
 * @property string $agency
 * @property string $reserve
 * @property string $reserve_dt
 * @property string $site_status
 * @property integer $last_user_id
 * @property string $last_change_dt
 * @property integer $country
 *
 * The followings are the available model relations:
 * @property ListCity $city
 * @property ListCityDistricts $district
 * @property ListCountry $country0
 * @property ListType $typeRealty
 * @property RealtyDesc[] $realtyDescs
 */
class RealtyBase extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'realty_base';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('dt_start, dt_add, type_realty, city_id, district_id, cost, furniture, cooperation, last_call, repair, phone, last_user_id, last_change_dt', 'required'),
			array('type_realty, city_id, district_id, cost, repair, send_count, last_user_id, country', 'numerical', 'integerOnly'=>true),
			array('furniture, cooperation, subscribe_advert, take, demo, daily, fordeleting, status, agency, reserve, site_status', 'length', 'max'=>1),
			array('call_status', 'length', 'max'=>20),
			array('phone', 'length', 'max'=>12),
			array('take_dt, demo_dt, reserve_dt', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('realty_id, dt_start, dt_add, type_realty, city_id, district_id, cost, furniture, cooperation, call_status, last_call, subscribe_advert, repair, phone, take, take_dt, demo, demo_dt, daily, send_count, fordeleting, status, agency, reserve, reserve_dt, site_status, last_user_id, last_change_dt, country', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'city' => array(self::BELONGS_TO, 'ListCity', 'city_id'),
			'district' => array(self::BELONGS_TO, 'ListCityDistricts', 'district_id'),
			'country0' => array(self::BELONGS_TO, 'ListCountry', 'country'),
			'typeRealty' => array(self::BELONGS_TO, 'ListType', 'type_realty'),
			'realtyDescs' => array(self::HAS_MANY, 'RealtyDesc', 'realty_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'realty_id' => 'Realty',
			'dt_start' => 'Dt Start',
			'dt_add' => 'Dt Add',
			'type_realty' => 'Type Realty',
			'city_id' => 'City',
			'district_id' => 'District',
			'cost' => 'Cost',
			'furniture' => 'Furniture',
			'cooperation' => 'Cooperation',
			'call_status' => 'Call Status',
			'last_call' => 'Last Call',
			'subscribe_advert' => 'Subscribe Advert',
			'repair' => 'Repair',
			'phone' => 'Phone',
			'take' => 'Take',
			'take_dt' => 'Take Dt',
			'demo' => 'Demo',
			'demo_dt' => 'Demo Dt',
			'daily' => 'Daily',
			'send_count' => 'Send Count',
			'fordeleting' => 'Fordeleting',
			'status' => 'Status',
			'agency' => 'Agency',
			'reserve' => 'Reserve',
			'reserve_dt' => 'Reserve Dt',
			'site_status' => 'Site Status',
			'last_user_id' => 'Last User',
			'last_change_dt' => 'Last Change Dt',
			'country' => 'Country',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('realty_id',$this->realty_id,true);
		$criteria->compare('dt_start',$this->dt_start,true);
		$criteria->compare('dt_add',$this->dt_add,true);
		$criteria->compare('type_realty',$this->type_realty);
		$criteria->compare('city_id',$this->city_id);
		$criteria->compare('district_id',$this->district_id);
		$criteria->compare('cost',$this->cost);
		$criteria->compare('furniture',$this->furniture,true);
		$criteria->compare('cooperation',$this->cooperation,true);
		$criteria->compare('call_status',$this->call_status,true);
		$criteria->compare('last_call',$this->last_call,true);
		$criteria->compare('subscribe_advert',$this->subscribe_advert,true);
		$criteria->compare('repair',$this->repair);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('take',$this->take,true);
		$criteria->compare('take_dt',$this->take_dt,true);
		$criteria->compare('demo',$this->demo,true);
		$criteria->compare('demo_dt',$this->demo_dt,true);
		$criteria->compare('daily',$this->daily,true);
		$criteria->compare('send_count',$this->send_count);
		$criteria->compare('fordeleting',$this->fordeleting,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('agency',$this->agency,true);
		$criteria->compare('reserve',$this->reserve,true);
		$criteria->compare('reserve_dt',$this->reserve_dt,true);
		$criteria->compare('site_status',$this->site_status,true);
		$criteria->compare('last_user_id',$this->last_user_id);
		$criteria->compare('last_change_dt',$this->last_change_dt,true);
		$criteria->compare('country',$this->country);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return RealtyBase the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
